﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using CRM.Entity;
using CRM.BLL;
using DP.Web.UI;
using DP.Common;


namespace CRM.Web.AppointmentReminderManage
{
    public partial class Handle : Common.PageBase
    {

        T_APPOINTMENTREMINDER_BLL bll = new T_APPOINTMENTREMINDER_BLL();
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            PageHelper.SetPrePageUrl(this.Page);
            PageHelper.SetGoBackUrl(this.Page, btnCancel); 
            txtAPPOINTMENTTIME.Attributes.Add("onfocus", "WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',errDealMode:'1'})");
            txtREMINDERTIME.Attributes.Add("onfocus", "WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',errDealMode:'1'})");
            //PageHelper.SetPopCalender(this.Page, txtAPPOINTMENTTIME);
            //PageHelper.SetPopCalender(this.Page, txtREMINDERTIME);
            //PageHelper.SetPopCalender(this.Page, txtCOMPLETIONTIME);
            //PageHelper.SetPopCalender(this.Page, txtCREATETIME);

        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
             


                pageDataInit();
            }
        }

        #region 页面初始化数据绑定





        #endregion

        private void pageDataInit()
        {
            string _appointmentreminderid = String.IsNullOrEmpty(Request.QueryString["APPOINTMENTREMINDERID"]) ? "" : Request.QueryString["APPOINTMENTREMINDERID"].Trim();

            if (!String.IsNullOrEmpty(_appointmentreminderid))
            {
                T_APPOINTMENTREMINDER_Entity entity = bll.GetEntity("APPOINTMENTREMINDERID", _appointmentreminderid);

                PageHelper.SetControlValue<T_APPOINTMENTREMINDER_Entity>(this.Page, entity);
                txtAPPOINTMENTTIME.Enabled = false;
            }


        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            string _appointmentreminderid = String.IsNullOrEmpty(Request.QueryString["APPOINTMENTREMINDERID"]) ? "" : Request.QueryString["APPOINTMENTREMINDERID"].Trim();


            T_APPOINTMENTREMINDER_Entity entity = bll.GetEntity("APPOINTMENTREMINDERID", _appointmentreminderid);
            Button btn = sender as Button;
            if (btn == null)
            {
                return;
            }
            switch (btn.CommandName)
            {
                case "Save":
                    {
                        if (entity != null)
                        {
                            PageHelper.GetControlValue<T_APPOINTMENTREMINDER_Entity>(this.Page, ref entity);


                            long rel = bll.Update(entity);
                            if (rel > 0)
                            {
                                PageHelper.ShowMessage(this.Page, "修改成功！", UserLoginInfo.FilterBackUrl(PageHelper.GetPrePageUrl(this), "list.aspx"));
                            }
                            else
                            {
                                PageHelper.ShowMessage(this.Page, "修改失败！");
                            }
                        }
                    }
                    break;
                case "Complete":
                    {
                        entity.STATUS = ((int)AppointmentReminderStatus.完成);
                        long rel = bll.Update(entity);
                        if (rel > 0)
                        {
                            PageHelper.ShowMessage(this.Page, "修改成功！", UserLoginInfo.FilterBackUrl(PageHelper.GetPrePageUrl(this), "list.aspx"));
                        }
                        else
                        {
                            PageHelper.ShowMessage(this.Page, "修改失败！");
                        }
                    }
                    break;
            }

            
          
        }
    }
}
